from openai.types.chat import ChatCompletionChunk
from openai import _streaming


async def async_generate_response(
    history: list[list[str]], stream: _streaming.AsyncStream[ChatCompletionChunk]
):
    async for chunk in stream:
        delta_content = chunk.choices[0].delta.content
        if delta_content is not None:
            yield delta_content
            history[-1][1][0]["text"] += delta_content
